		;.export _main

         ;*= $1000
        processor 6502
        org $900
scr = $400
gscr = $6000

color = $d800
music = $1000
b = $4000
b0 = $6400
b1 = $8c00

_main:	
         sei
         
         lda #$16
         sta $d018
         
         
         lda #0
         sta $d021
         
         lda #32
         jsr cls
         
         ;jsr copy
         lda #$36
         sta $01 ; switch out basic
         
         lda #0
         jsr $1000
main
		lda #$ff
         cmp $d012
         bne main

         lda #0
         sta $d020
         
         lda #$38
         sta $d011
         lda #$10
         sta $d016
         lda #$80
         sta $d018
         
         lda #$02
         sta $dd00 ; vic-bank
         
         jsr music+3

		inc $d020

		
		jsr scroll
		inc $d020
		
		inc varv
		bne nocopy
		jsr copy
nocopy
		
		inc $d020
		
		lda xpos
		and #$07
		tax
		ldy #$16
		
		lda #230
w2		cmp $d012
		bne w2
		inc $d020
		
		stx $d016
        sty $d018
 
        lda #$03
        sta $dd00 ; vic-bank
       
        lda #$18
        sta $d011 ; char mode
        
        
    
		
		
         inc $d020
         jmp main

varv	.byte 0

cls
		ldx #0
clsl	
		sta scr,x
		sta scr+250,x
		sta scr+500,x
		sta scr+750,x
		inx
		cpx #250
		bne clsl
		
		lda #$1
		ldx #0
cls2	sta color,x
		sta color+250,x
		sta color+500,x
		sta color+750,x
		inx
		cpx #250
		bne cls2
		rts

;-------------------------------
; 
;
;
;
b0b1	.byte #$ff

copy
		ldy #0
		ldx #0
				;ldx cp
		inc b0b1
		bne bild2
		
		lda #<b0
		sta pb0+1
		lda #>b0
		sta pb0+2
		
		lda #<b
		sta pb+1
		lda #>b
		sta pb+2
		
		lda b0+10000
		sta $d021
		
				ldx #0
lcopy	
		
		lda b0+8000,x
		sta gscr,x
		
		lda b0+8000+250,x
		sta gscr+250,x
		
		lda b0+8000+500,x
		sta gscr+500,x
		
		lda b0+8000+750,x
		sta gscr+750,x
		
		
		lda b0+8000+1000,x
		sta color,x
		
		lda b0+8000+1000+250,x
		sta color+250,x
		
		lda b0+8000+1000+500,x
		sta color+500,x
		
		lda b0+8000+1000+750,x
		sta color+750,x
		
		inx
		cpx #250
		bne lcopy
		
		jmp bcopy
		
bild2
		lda #<b1
		sta pb0+1
		lda #>b1
		sta pb0+2
		
		lda #<b
		sta pb+1
		lda #>b
		sta pb+2
		
		
		lda b1+10000
		sta $d021
		
		ldx #0
lcopy1	
		lda b1+8000,x
		sta gscr,x
		
		lda b1+8000+250,x
		sta gscr+250,x
		
		lda b1+8000+500,x
		sta gscr+500,x
		
		lda b1+8000+750,x
		sta gscr+750,x
			
		lda b1+8000+1000,x
		sta color,x
		
		lda b1+8000+1000+250,x
		sta color+250,x
		
		lda b1+8000+1000+500,x
		sta color+500,x
		
		lda b1+8000+1000+750,x
		sta color+750,x
		inx
		cpx #250
		bne lcopy1
		
		lda #$ff
		sta b0b1

;copy
		
bcopy		
pb0		lda b0,x
		;lda #$55
pb		sta b,x
		;inc $d020
		inx
		bne bcopy
		
		inc pb0+2
		inc pb+2
		iny
		cpy #30
		bne bcopy
		
;		rts ; fixme!
		

		
		rts
cp		.byte 0
bp		.byte 0

;---------------------------------------
scroll
         lda xpos
         ;cmp #$ff
         bne smooth

         ldx #0
csroll
         lda 1985,x
         sta 1984,x
         inx
         cpx #38
         bne csroll

         lda #$08
         sta xpos

         ldx tpos
tp       lda txt,x
         bne tok
         inc $d020
         lda #<txt
         sta tp+1
         lda #>txt
         sta tp+2
         lda #0
         sta tpos
         ;lda txt

tok      ;and #127
         ;ora #128
         ;ora #32
         sta 2022
         inc tpos
         bne endscroll
         inc tp+2
endscroll
smooth
         ;lda xpos
         ;sta $d016
         dec xpos

         rts

xpos     .byte 7
tpos     .byte 0


		
         ;*= $2000
         
         
txt
         ;.text "0123456789"
         ;.byte 0
         ;.text 
         .byte "CCC PRESENTS ...... "
         ;.text 
         .byte "A MUMU21 "

         ;.text 
         .byte "PRODUCTION....  "
         ;.text 
         .byte "MUELLENDORF BY NIGHT "
         ;.text 
         .byte "........"
         ;.text 
         .byte " THE ULTRA COOL GAME "
         ;.text 
         .byte "        "
         ;.text 
         .byte "NO NEED TO CRACK IT, "
         ;.text 
         .byte "WE ALREADY DID!      "

         .byte 0
	
		
		;org $1000
;music		.incbin "../../work/music/muzak.prg"
		
		;org $1000




















